﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Baosight.Ccs.Mail
{
    public class ProcessMailManager
    {

        private IMailHandler mailHander = null;

        public IMailHandler MailHander
        {
            get { return mailHander; }
            set { mailHander = value; }
        }

        public void ProcessMail()
        {
            List<Mail> mailsToProcess = MailManager.Instance.GetMailsByStatus(MailStatus.Unhandled);
            mailsToProcess.ForEach(
                delegate(Mail mail)
                {
                    try
                    {

                        mailHander.Process(mail);
                    }
                    catch (Exception ex)
                    {
                        ExceptionPolicy.HandleException(ex, MailConstants.ProcessMailFailExceptionPolicy);
                    }
                }
              );

        }
    }
}
